<?php
include 'database.php'; //数据库的配置信息
require 'lianjie.php';  // 数据库的操作函数
$con = lianjieshujuku($servername, $name, $passwd);//连接数据库

$mac = $_GET['mac'];
$username = $_GET['username'];


$path = "floweruser/" . $username . "/" . $mac;
$picpath = "floweruser/" . $username;

//其实呢就是看receive　创建了啥就删除啥

//删除图片
echo $picpath."/".$mac.".jpg";
if (file_exists($picpath."/".$mac.".jpg")) {
    unlink($picpath."/".$mac.".jpg");
    echo "图片删除成功";
}

//fname 删除
if (!mysqli_select_db($con, 'flower')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "DELETE FROM `fname` WHERE `mac`='$mac'");
if ($req) {
    echo "fname成功";
}


//flowdate删除
if (!mysqli_select_db($con, 'flowdate')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "DROP TABLE  `$mac`");
if ($req) {
    echo "flowdate成功";
}
//user
if (!mysqli_select_db($con, 'floweruser')) {
    die("选择数据库失败");
}
$req = mysqli_query($con, "SELECT * from `user` WHERE `username`='$username'");
$jieguo = mysqli_fetch_array($req);
$oldmac = $jieguo['flowers'];
print_r($oldmac);
$old_array = explode("|",$oldmac);
print_r($old_array);

$new_flowerlist="";
foreach ($old_array as $old_flower){
    if($old_flower!="$mac"){
        echo "<br>";
        echo $old_flower;
        if($new_flowerlist==""){
            $new_flowerlist = $old_flower;
        }else{
            $new_flowerlist = $new_flowerlist."|".$old_flower;
        }

    }
}
echo "<br>";
echo $new_flowerlist;

$req = mysqli_query($con, "UPDATE `user` SET `flowers`='$new_flowerlist' WHERE `username`='$username'");
if ($req) {
    echo 'user成功';
}

